package org.skyemoon.hbase.hbasetest.config;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.springframework.context.annotation.Bean;

import java.io.IOException;

import static org.skyemoon.hbase.hbasetest.common.constant.HbaseConnectionConstant.HOST;
import static org.skyemoon.hbase.hbasetest.common.constant.HbaseConnectionConstant.ZK_PORT;

/**
 * Hbase连接配置
 */
@org.springframework.context.annotation.Configuration
public class HbaseConfiguration {

    /**
     * 创建Hbase重量级连接
     * @return connection
     */
    @Bean
    //TODO 写入文件后内存不断增加不释放 写入操作存在内存泄漏？ 参照es方式修改后验证
    public Connection createHbaseConnection() {
        Configuration configuration = HBaseConfiguration.create();
        configuration.set("hbase.zookeeper.quorum", HOST);
        configuration.set("hbase.zookeeper.property.clientPort", ZK_PORT);
        Connection connection;
        try {
            connection = ConnectionFactory.createConnection(configuration);
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
        return connection;
    }
}
